package spitfire;
import java.awt.event.KeyEvent;

import light3d.*;
import light3d.*;

public class LandScapeTestClass
{
	public static void main(String[] args)
	{
		SpitfireLandscape engineWindow = new SpitfireLandscape();
		SpitfireBufferedCanvas bufferedCanvas = engineWindow; 

		PointWithAngle camera = new PointWithAngle(0,35,0);
		camera.finalizeCoordinates();

		final int MAX_RUNS = 3, FRAMES_PER_RUN = 100;
		
		WavefrontMesh testMesh = new WavefrontMesh("data/fighter.obj");
		testMesh.setY(30);
		
		double timePassed = 0.0;
		
		//Building myBuild = new Building(bufferedCanvas,0,0,2.5,2.5,10);
		//Building myBuild = new Building(bufferedCanvas,0,0,25,25,10);
		
		for (int r = 0; r < MAX_RUNS || true; r++)
		{
			for (int f = 0; f < FRAMES_PER_RUN; f++)
			{
				double angle = (f + FRAMES_PER_RUN*r)*360/MAX_RUNS/FRAMES_PER_RUN;
				bufferedCanvas.setCameraLocation(camera);
				bufferedCanvas.beginRender();
				
				testMesh.setPosition(0, 30, -150);
				testMesh.applyColor(BufferedCanvas.getRGBColor(255, 0, 0));
				testMesh.render(bufferedCanvas, camera);
				
				testMesh.applyColor(BufferedCanvas.getRGBColor(0, 0, 255));
				testMesh.setPosition(0, 30, 150);
        testMesh.rotate(0, f * 360/FRAMES_PER_RUN, 0);
				testMesh.render(bufferedCanvas, camera);
				testMesh.resetChanges();
				
				//myBuild.render(bufferedCanvas, camera);
				
				timePassed = bufferedCanvas.endRender(bufferedCanvas, camera);
				
				if (engineWindow.isPressed(KeyEvent.VK_LEFT))
				{
					//camera.rotate(-90*timePassed, 0, 0);
					camera.rotate(0,90*timePassed, 0);
					//camera.rotate(0,0,-90*timePassed);
				}

				if (engineWindow.isPressed(KeyEvent.VK_RIGHT))
				{
					//camera.rotate(90*timePassed, 0, 0);
					camera.rotate(0,-90*timePassed, 0);
					//camera.rotate(0,0,90*timePassed);
				}
				
				if (engineWindow.isPressed(KeyEvent.VK_UP))
				{
					camera.rotate(-90*timePassed, 0, 0);
				}
				
				if (engineWindow.isPressed(KeyEvent.VK_DOWN))
				{
					camera.rotate(90*timePassed, 0, 0);
				}				
				if (engineWindow.isPressed(KeyEvent.VK_W))
				{
					camera.moveForwards(25*timePassed);
				}
				if (engineWindow.isPressed(KeyEvent.VK_S))
				{
					camera.moveForwards(-25*timePassed);
				}
				if (engineWindow.isPressed(KeyEvent.VK_A))
				{
					camera.rotate(0, 0, -90*timePassed);
				}
				if (engineWindow.isPressed(KeyEvent.VK_D))
				{
					camera.rotate(0, 0, 90*timePassed);
				}				
			}
			bufferedCanvas.printStatistics();
		}
		System.exit(0);
	}
}
